package com.qiyu.jvm.reference;

/**
 * 引用计数
 *
 * @Author linhao
 * @Date created in 2:48 下午 2021/1/4
 */
public class ReferenceCounting {

    private  Object instance = null;

    private static final int _1MB = 1024 * 1024;

    private byte[] bigSize = new byte[2 * _1MB];

    public static void testGC(){
        ReferenceCounting referenceCountingA = new ReferenceCounting();
        ReferenceCounting referenceCountingB = new ReferenceCounting();
        referenceCountingA.instance = referenceCountingB;
        referenceCountingB.instance = referenceCountingA;

        referenceCountingA = null;

        referenceCountingB = null;

        System.gc();
    }

    public static void main(String[] args) {
        testGC();
    }
}
